package org.ysu.shoeShopping.service.impl;

import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.ysu.shoeShopping.dao.ShoePhotosDao;
import org.ysu.shoeShopping.entity.ShoePhotos;
import org.ysu.shoeShopping.service.ShoePhotosService;

import javax.annotation.Resource;

/**
 * 鞋图片表(ShoePhotos)表服务实现类
 *
 * @author makejava
 * @since 2025-09-13 16:59:36
 */
@Service("shoePhotosService")
public class ShoePhotosServiceImpl implements ShoePhotosService
{
    @Resource
    private ShoePhotosDao shoePhotosDao;

    /**
     * 通过ID查询单条数据
     *
     * @param spid 主键
     * @return 实例对象
     */
    @Override
    public ShoePhotos queryById(Integer spid) {
        return this.shoePhotosDao.queryById(spid);
    }

    /**
     * 分页查询
     *
     * @param shoePhotos 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<ShoePhotos> queryByPage(ShoePhotos shoePhotos, PageRequest pageRequest) {
        long total = this.shoePhotosDao.count(shoePhotos);
        return new PageImpl<>(this.shoePhotosDao.queryAllByLimit(shoePhotos, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param shoePhotos 实例对象
     * @return 实例对象
     */
    @Override
    public ShoePhotos insert(ShoePhotos shoePhotos) {
        this.shoePhotosDao.insert(shoePhotos);
        return shoePhotos;
    }

    /**
     * 修改数据
     *
     * @param shoePhotos 实例对象
     * @return 实例对象
     */
    @Override
    public ShoePhotos update(ShoePhotos shoePhotos) {
        this.shoePhotosDao.update(shoePhotos);
        return this.queryById(shoePhotos.getSpid());
    }

    /**
     * 通过主键删除数据
     *
     * @param spid 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer spid) {
        return this.shoePhotosDao.deleteById(spid) > 0;
    }
}
